package DMSXL._2023Before.DoubleLnode;

public class reverseWords_ {
    public static void main(String[] args) {
        String s = "a good   example";
        Solution solution = new Solution();

    }
}
/*class Solution {
    public String remove_(String s){
        char[] str = s.toCharArray();
        int slow = 0;
        for (int i = 0; i < s.length(); i++) {
            if(str[i] != ' '){
                if(slow != 0)
                    str[slow++] = ' ';
                while(i < s.length() && str[i] != ' '){
                    str[slow++] = str[i++];
                }
            }
        }
        return new String(str,0,slow);
    }
    public void reverse(char[] ch,int start,int end){
        int len = (end - start)+1;
        for (int i = 0; i < len/2; i++) {
            char temp = ch[start];
            ch[start] = ch[end];
            ch[end] = temp;
            start++;
            end--;
        }
    }
    public String reverseWords(String s) {
        if(s.length() == 0)
            return s;

        s = remove_(s);
        char[] ch = s.toCharArray();
        char[] newch = new char[ch.length];

        for (int i = 0,k = ch.length - 1; i < ch.length ; i++,k--) {
            newch[k] = ch[i];
        }
        int start = 0,end = 0;
        while (end < s.length()){
            if(newch[end] != ' ' && end != s.length() - 1)
                end++;
            else if(newch[end] == ' ' || end == s.length() - 1){
                if(end == s.length() - 1)
                    reverse(newch,start,end );
                else
                    reverse(newch,start,end - 1);
                end++;
                start = end;
            }
        }

        return String.valueOf(newch);
    }
}*/
